package com.ruoyi.web.core.config;

import com.github.alenfive.rocketapi.entity.ApiInfo;
import com.ruoyi.common.utils.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;

// @Component
// @Aspect
public class RequestMappingInfoAop {
    // @Around("execution(* com.github.alenfive.rocketapi.service.RequestMappingService.registerMappingForApiInfo(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        System.out.println("aop");

        if (!(joinPoint.getArgs()[0] instanceof ApiInfo)) {
            return joinPoint.proceed();
        }
       ApiInfo apiInfo = ((ApiInfo)joinPoint.getArgs()[0]);
       String tempFullPath = null;

        if (StringUtils.isNotEmpty(apiInfo.getFullPath()) &&
                apiInfo.getFullPath().lastIndexOf("?") > -1) {
            tempFullPath = apiInfo.getFullPath();
            apiInfo.setFullPath(tempFullPath.substring(0,tempFullPath.indexOf("?")));
        }

        final Object proceed = joinPoint.proceed();

        if (StringUtils.isNotEmpty(tempFullPath)) {
            apiInfo.setFullPath(tempFullPath);
        }

        return proceed;
    }

}
